﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using CellphoneRepair.DAL;
using CellphoneRepair.Entities;
using DevExpress.XtraEditors;
using DevExpress.XtraReports.UI;

namespace CellphoneRepair.Forms
{
    public partial class EditList : DevExpress.XtraEditors.XtraForm
    {
        private BindingSource bindingSource;

        public EditList(BindingSource repairlistBindingSource)
        {
            InitializeComponent();
            bindingSource = repairlistBindingSource;
        }

        public EnumEditType editType { get; set; }

        private void EditList_Load(object sender, EventArgs e)
        {
            var obj = bindingSource.Current as Repairlist;

            if (editType == EnumEditType.Create)
            {
            }
            else
            {
                using (KehuBll bll = new KehuBll())
                {
                    var kehu = bll.GetByKey(obj.Idkehu);

                    kehuBindingSource.DataSource = kehu;
                }
            }
        }

        public Kehu CurKehu { get; set; }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Kehuselector kl = new Kehuselector();
            kl.Tag = this;
            if (kl.ShowDialog() == DialogResult.OK)
            {
                List<Kehu> list = new List<Kehu>() {CurKehu};
                kehuBindingSource.DataSource = list;
            }
        }

        private EnumEditType PhoneEditType { get; set; }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            PhoneEditType = EnumEditType.Create;

            gridView1.AddNewRow();
            gridView1.ShowEditForm();
        }

        public string xinghao { get; set; }

        private void xinghaoSelect_Enter(object sender, EventArgs e)
        {
            XinghaoSelector xs = new XinghaoSelector();
            xs.Tag = this;
            if (xs.ShowDialog() == DialogResult.OK)
            {
                 gridView1.SetRowCellValue(repairedBindingSource.Position,"xinghao",xinghao);
            }
        }

        private void repairedBindingSource_AddingNew(object sender, AddingNewEventArgs e)
        {
            Repaired repaired = new Repaired();
            repaired.Idrepaird = Commons.GenerateIdByForeTag("SJ");
            repaired.Idlist = (bindingSource.Current as Repairlist).Idlist;
            e.NewObject = repaired;
        }

        private void simpleButton7_Click(object sender, EventArgs e)
        {
            RptView rv = new RptView();
            rv.bindingSource1 = kehuBindingSource;
            rv.bindingSource2 = repairedBindingSource;
            ReportPrintTool tool = new ReportPrintTool(rv);
            tool.ShowPreview();
        }
    }
}